package org.example.springweibo.service;

import org.example.springweibo.exception.ServiceException;
import org.example.springweibo.mapper.CommentMapper;
import org.example.springweibo.pojo.dto.CommentDTO;
import org.example.springweibo.pojo.entity.Comment;
import org.example.springweibo.pojo.vo.WeiboCommentVO;
import org.example.springweibo.serviceode.ServiceCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentService {

    @Autowired
    private CommentMapper commentMapper;

    public int addComment(Comment comment){
        if (comment.getContent()==null) {
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND,"输入参数错误");
        }
        comment.setCreated(new Date());
        return commentMapper.addComment(comment);
    }

    public int deleteComment(Comment comment) {
        return commentMapper.deleteComment(comment.getId());
    }

    public List<WeiboCommentVO> selectCommentByUser(CommentDTO commentResult) {
        return commentMapper.selectCommentByMyUser(commentResult);
    }
}
